package com.zzptc.syl.viewpager;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.LineData;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link TwoFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class TwoFragment extends Fragment {

    //创建集合
    private List<BarEntry> data = new ArrayList<>();
    public static TwoFragment newInstance() {
        TwoFragment fragment = new TwoFragment();
        Bundle args = new Bundle();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        //绑定视图
        View inflate = inflater.inflate(R.layout.fragment_two, container, false);
        //实例化控件
        BarChart barChart = inflate.findViewById(R.id.barChart);
        //将数据添加至集合
        data.add(new BarEntry(7,9));
        data.add(new BarEntry(3,5));
        data.add(new BarEntry(5,8));

        //设置数据
        BarDataSet one = new BarDataSet(data,"第一个");
        //建立一个数组
        BarData barData = new BarData();
        //将数据放入至数组里
        barData.addDataSet(one);
        //将数组添加至条形图中
        barChart.setData(barData);
        return inflate;
    }
}